home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / dsp / dr.bub / 96000.lha / 96000 / appb / b144.asm < prev    next >
Assembly Source File  |  1992-04-28  |  54KB  |  1,062 lines

  1. ; This program was originally published in the Motorola DSP96002 Users Manual
  2. ; and is provided under a DISCLAIMER OF WARRANTY available from Motorola DSP
  3. ; Operation, 6501 William Cannon Drive West, Austin, Texas 78735-8598.  For
  4. ; more information, refer to the DSP96002 Users Manual, Appendix B, DSP
  5. ; Benchmarks.
  6. ;
  7. ; B.1.44    Wire-Frame Graphics Rendering  
  8. ;         WIRE-FRAME RENDITION OF A THREE DIMENSIONAL POLYLINE 
  9. ;                     ON THE MOTOROLA DSP96002  
  10. ;                         Version 1.00 
  11. ;
  12. ;OVERVIEW  
  13. ;This program displays a three dimensional polyline in two dimensions.  The points of the polyline, as 
  14. ;defined in the input list, are  projected into two dimensions using the perspective transformation.  
  15. ;The projected points are output to a display list that can be drawn  by a graphics engine or a fast 
  16. ;drawing program.  
  17. ;In order to maximize speed, two loops perform the graphics  transformations:  the trivial accept loop 
  18. ;and the trivial reject loop.  
  19. ;The trivial accept loop assumes that the last displayed point was  inside the viewing pyramid and thus 
  20. ;not clipped.  It pulls a new  point from the input list, converts it to clipping space and checks  if it is 
  21. ;inside the viewing pyramid.  If so, the routine performs  the perspective transformation, scales and 
  22. ;translates the point so  it lies within the viewing window, and finally adds it to the  display list.  
  23. ;If the point is found to lie outside the viewing pyramid, an  algorithm to clip a single point is per-
  24. ;formed and the program  enters the trivial reject loop.  
  25. ;The trivial reject loop assumes that the last displayed point was  outside the viewing pyramid.  It pulls 
  26. ;a new point from the input  list, converts it to clipping space and checks if the line joining  the new 
  27. ;point and the last point can be trivially rejected.  Trivial rejection occurs when both points of a line lie 
  28. ;outside of  a clipping plane.  When this occurs, the current point is saved  and the trivial reject loop 
  29. ;repeats.  
  30. ;Should the line not be trivially rejected but the current point  is accepted, an algorithm to clip a single 
  31. ;point is performed.  If  the current point is not accepted,  two-point clipping is  performed.  
  32. ;PERFORMANCE  
  33. ;All times are given in instruction cycles.  
  34. ;  Accept loop 
  35. ;    First point                       38 
  36. ;    Each additional point             39 
  37. ;  Accept single point clip 
  38. ;    Minimum (single plane)            68 
  39. ;    Maximum (three planes)            94 
  40. ;  Reject loop 
  41. ;    Each point                        37 
  42. ;  Reject single point clip 
  43. ;    Minimum (single plane)            89 
  44. ;    Maximum (three planes)           115 
  45. ;  Reject double clip line drawn 
  46. ;    Minimum (two single planes)      145 
  47. ;    Maximum (six planes)             206 
  48. ;  Reject double clip line rejected 
  49. ;    Minimum (two single planes)      112 
  50. ;    Maximum (six planes)             173 
  51. ;
  52. ;The DSP96002 has an instruction cycle time of 74ns and will  transform 347K points/sec in the ac-
  53. ;cept loop.  In the reject loop,  365K points can be rejected each second.  
  54. ;INPUT  
  55. ;Before calling the polyline generator, address register r1 should  point to the area in X memory which 
  56. ;contains the X, Y and Z  coordinates of the input points.  Data register d7.l should  contain the num-
  57. ;ber of points in the polyline in the form of a  32-bit integer.  
  58. ;OUTPUT  
  59. ;Address register r5 should point to a display list data area when  the polyline generator is called.  Af-
  60. ;terwards, the display list will  be in the following format:  
  61. ;  Polygon1:  X1,Y1 
  62. ;             X2,Y2 
  63. ;             X3,Y3 
  64. ;                                       Xn,Yn 
  65. ;  Delimiter  -1.0 
  66. ;  Polygon2:  X1,Y1 
  67. ;             X2,Y2 
  68. ;                            Delimiter  -1.0 
  69. ;            PolygonM:  X1,Y1 
  70. ;              
  71. ;             Xn,Yn 
  72. ;             -2.0 
  73. ;
  74. ;All coordinates are in IEEE single-precision floating-point format to  speed up the DSP96002 float-
  75. ;ing-point incremental line drawing algorithm.  
  76. ;ADDRESS REGISTER USAGE  
  77. ;Four address registers are used:  
  78. ;  r0    input list 
  79. ;  r1    temporary coordinates 
  80. ;  r4    transformation matrix, scale and offset for 2D transformation 
  81. ;  r5    output list 
  82. ;  r6    miscellaneous scratchpad memory 
  83. ;
  84. ;The following memory map results:  
  85. ;                X Memory     Y Memory 
  86. ;          r0   ?    Xobj0 
  87. ;          n0=0.0 Yobj0 
  88. ;                 Zobj0 
  89. ;                 Xobj1 
  90. ;                                     
  91. ;          r1 ?    Xnew         Znew 
  92. ;          n1=2   Ynew         Wnew 
  93. ;          m1=3   Xold         Zold 
  94. ;                 Yold         Wold 
  95. ;          r4 ?                    Matrix1,1 
  96. ;          n4=2   Matrix4,1    Matrix2,1 
  97. ;          m4=13               Matrix3,1 
  98. ;                              Matrix1,2 
  99. ;                 Matrix4,2    Matrix2,2 
  100. ;                              Matrix3,2 
  101. ;                              Matrix1,3 
  102. ;                 Matrix4,3    Matrix2,3 
  103. ;                              Matrix3,3 
  104. ;                              Matrix1,4 
  105. ;                 Matrix4,4    Matrix2,4 
  106. ;                              Matrix3,4 
  107. ;                 Xscale       Xoffset 
  108. ;                 Yscale       Yoffset 
  109. ;                              Xout0   ?  r5 
  110. ;                              Yout0     n5=-1.0 
  111. ;                              Xout1 
  112. ;                              Yout1 
  113. ;                                                             
  114. ;                 TempCount    TOld,Xtemp ? r6  (temporaries) 
  115. ;                              Ytemp 
  116. ;                              Wtemp 
  117. ;
  118. ;Several registers hold constants that speed up calculations.  These are:  
  119. ;  d8 =  1.0 for double point clipping 
  120. ;  d9 =  2.0 for division 
  121. ;  n0 =  0.0 for z limit test and double point clipping 
  122. ;  n5 = -1.0 for end of polyline marker 
  123. ;
  124. ;TRIVIAL ACCEPT LOOP  
  125. ;The transformation from object space to screen space is performed  in lines 19-33.  This is a 
  126. ;{1x4}{4x4} matrix multiplication but  because the W coordinate of the {1x4} input vector {X Y Z W} is  
  127. ;always equal to one, four multiplications can be eliminated.  
  128. ;Lines 39-47 determine if the point is within the viewing pyramid.  The FCMP s,d instruction is de-
  129. ;signed to clear the sticky accept  (A) bit (bit 7 in the CCR) whenever s > d.  By switching the order  
  130. ;of the operands, the FCMP instruction can be used to test both the  maximum and minimum bound-
  131. ;aries of a window.  To test acceptance,  the A bit is set in line 40 and the X and Y coordinates are  
  132. ;compared to the boundaries -W and W.  The Z coordinate is compared  to the boundaries 0 and W.  
  133. ;If the A bit remains set, the point is  within the viewing pyramid and is transformed to screen  coordi-
  134. ;nates.  
  135. ;If the A bit is clear, the reject loop is entered.  Note that the  A bit is only affected by the CMP, 
  136. ;CMPG, FCMP and FCMPG instructions.  
  137. ;The reciprocal 1/W is calculated in lines 53-58.  The result is  accurate to approximately 32 bits.  It is 
  138. ;multiplied by the X  coordinate and then by the X scale to scale the data to the output  screen.  The 
  139. ;coordinate is then translated to screen space.  The  procedure is repeated for the Y coordinate and 
  140. ;the coordinates  are added to the display list.  
  141. ;For additional points the accept loop code is almost identical to  the first point code except that if 
  142. ;the new point is not within  the viewing pyramid, a jump to a single point clipping routine is  per-
  143. ;formed.  
  144. ;ACCEPT LOOP SINGLE POINT CLIPPING CODE  
  145. ;The method used for clipping a line when one point is inside the  viewing pyramid and one point is 
  146. ;outside is a special case of a  general clipping algorithm presented in [1] and is used in the  double 
  147. ;point clipping code.  
  148. ;Suppose that the line between points P1 and P2 was rejected because  the x coordinate of P2, x2, 
  149. ;was larger than w2.  Then,  
  150. ;  y2 = y1 + t (y2 - y1) 
  151. ;where 
  152. ;  t  =         w1 - x1 
  153. ;        --------------------- 
  154. ;        (w1 - x1) - (w2 - x2) 
  155. ;Substituting the value of t results in the determinant 
  156. ;  y2 =   | y2  w2-y2 | 
  157. ;         | y1  w1-y1 | 
  158. ;      ------------------- 
  159. ;       (w1-x1) - (w2-x2) 
  160. ;
  161. ;The equations for z2 and w2 are analogous.  Since w2 has the same  denominator as x2, y2 and z2, 
  162. ;and these will be divided by w2 in the  perspective transformation, the division shown above does 
  163. ;not need  to be performed.  
  164. ;Lines 151-162 determine which planes that the point is outside and  call the appropriate clipping rou-
  165. ;tines.  These routines (lines 520-617)  calculate the determinants and return with the resulting coordi-
  166. ;nates in  the data registers.  
  167. ;The resulting point is transformed using the perspective  transformation, scaled and translated in 
  168. ;lines 168-186.  A code (-1.0)  is stored in the display list to indicate that the next line to be  drawn is 
  169. ;not joined with the current one.  Control is then transferred  to the trivial reject loop.  
  170. ;TRIVIAL REJECT LOOP  
  171. ;The trivial reject loop starts with the {1x4}{4x4} matrix  multiplication to transform the input point to 
  172. ;clipping space.  Next,  the line joining the current point and the previously rejected  point is tested 
  173. ;for trivial rejection.  As mentioned earlier,  trivial rejection occurs whenever both of the endpoints lie 
  174. ;outside  of one clipping plane.  
  175. ;A sticky bit called Local Reject (LR) is defined as bit 5 of the  CCR.  It is cleared by the FCMP s,d in-
  176. ;struction whenever s <= d.  In other words, the LR bit is cleared whenever the FCMP instruction  
  177. ;finds the coordinate inside of the boundary.  
  178. ;An additional instruction, FCMPG, is needed because trivial  rejection occurs when both points are 
  179. ;outside of any boundary  plane.  Thus, an additional sticky bit called Reject (R) (bit 6 of  the CCR) is 
  180. ;used to "remember" that a trivial reject has occurred  after comparisons against one boundary plane.  
  181. ;The FCMPG  instruction affects R and is performed as the last comparison to a  boundary plane.  
  182. ;When FCMPG s,d is executed, the R flag is cleared  if the previous point was outside of the bound-
  183. ;ary (LR is set) and  the current point is outside of the boundary (s > d).  The FCMPG  instruction al-
  184. ;so resets the LR bit to 1 for comparison to the next  boundary plane.  
  185. ;To perform the trivial reject test, the LR and R bits are set to 1.  The two points are tested against 
  186. ;the X = -W boundary plane and  then tested against the X = W plane etc.  The first point is tested  us-
  187. ;ing FCMP and the second point is tested using FCMPG to clear the  R bit if both comparisons were 
  188. ;outside of the boundary.  At the end  of these comparisons, if the R bit is 0, the line was trivially  re-
  189. ;jected.  With this definition, the trivial rejection test can be  generalized to a polygon with any number 
  190. ;of points.  The execution  time is of order 6N cycles where N is the number of points.  
  191. ;The lines 225-236 perform the trivial reject test.  Should the line  be trivially rejected, the new coordi-
  192. ;nates are stored for the next  comparison and the reject loop repeats.  
  193. ;If the line is not trivially rejected, a check is made to determine  if the current point is accepted.  If so, 
  194. ;control is transferred to  the reject loop single point clip routine.  Otherwise the double  point routine 
  195. ;is entered.  
  196. ;REJECT LOOP SINGLE POINT CLIPPING CODE  
  197. ;The reject loop single point clipping code is very similar to the  analogous code in the accept loop.  It 
  198. ;calls the same clipping  subroutines in lines 520-617.  Then the point that was just calculated  is trans-
  199. ;formed, scaled and translated and stored in the output list  (lines 305-321).  Finally, the new point 
  200. ;(which was accepted) is  transformed, scaled and translated (lines 327-345).  Control is  transferred 
  201. ;to the accept loop.  
  202. ;REJECT LOOP DOUBLE POINT CLIPPING CODE  
  203. ;Lines 359-492 are a direct implementation of a clipping algorithm  using endpoint coordinates given 
  204. ;in {1}.  The clipping method using  determinants is not powerful enough to handle the cases where 
  205. ;the  line is rejected but not trivially rejected.  Thus, the line  parameters t1 and t2 are calculated explic-
  206. ;itly.  The t1 parameter  is calculated based on the coordinates of the old point and the  t2 parameter 
  207. ;is calculated based on the current point.  
  208. ;These parameters are calculated by a set of double point clipping  subroutines in lines 631-853.  These 
  209. ;subroutines are called based  on the coordinates in lines 359-395.  
  210. ;The line is checked for rejection which occurs when t1 > t2.  If  the line is not rejected, the plane inter-
  211. ;sections are interpolated  based on t1 and t2 (lines 409-431).  Then the two new points are  trans-
  212. ;formed, scaled and translated in lines 437-478.  Control is  then transferred to the reject loop.  
  213. ;If the line is rejected, control is transferred to the reject loop  after some housekeeping is performed.  
  214. ;TERMINATION CODE  
  215. ;Lines 499-509 swallow the line delimiter code (-1.0) if it is the  last coordinate in the display list.  
  216. ;Then it adds the end of  display list code (-2.0) to the display list and exits.  
  217. ;REFERENCE  
  218. ;{1}  William M. Newman and Robert F. Sproull, Principles of Interactive 
  219. ;     Computer Graphics, (New York:  McGraw-Hill, 1979). 
  220. ;
  221. ;; WIRE-FRAME RENDITION OF A THREE DIMENSIONAL POLYLINE 
  222. ;               ON THE MOTOROLA DSP96002 
  223. ;           Version 1.00  18-Nov-88   
  224. ;--------------------------------------------------------- 
  225. ;                     First point 
  226. ;--------------------------------------------------------- 
  227.  
  228.  
  229. ; Transform to clip space 
  230. ;                                                                 Words     ICycles
  231. wf3d 
  232.   move                         x:(r0)+,d0.s                ;X       1  1 
  233.   move                         x:(r0)+,d5.s   y:(r4)+,d4.s ;Y   M11 1  1 
  234.   fmpy.s d4,d0,d2              x:(r4)+,d3.s   y:,d4.s      ;M41 M21 1  1 
  235.   fmpy   d4,d5,d3 fadd.s d3,d2 x:(r0)+,d6.s   y:(r4)+,d4.s ;Z   M31 1  1 
  236.   fmpy   d4,d6,d3 fadd.s d3,d2 x:(r1)+n1,d1.s y:(r4)+,d4.s ;r1+ M12 1  1 
  237.   fmpy   d4,d0,d1 fadd.s d3,d2 x:(r4)+,d3.s   y:,d4.s      ;M42,M22 1  1 
  238.   fmpy   d4,d5,d3 fadd.s d3,d1                y:(r4)+,d4.s ;    M32 1  1 
  239.   fmpy   d4,d6,d3 fadd.s d3,d1 d2.s,x:(r1)+   y:(r4)+,d4.s ;Xo  M13 1  1 
  240.   fmpy   d4,d0,d2 fadd.s d3,d1 x:(r4)+,d3.s   y:,d4.s      ;M43 M23 1  1 
  241.   fmpy   d4,d5,d3 fadd.s d3,d2                y:(r4)+,d4.s ;    M33 1  1 
  242.   fmpy   d4,d6,d3 fadd.s d3,d2 d1.s,x:(r1)-   y:(r4)+,d4.s ;Yo  M14 1  1 
  243.   fmpy   d4,d0,d1 fadd.s d3,d2 x:(r4)+,d3.s   y:,d4.s      ;M44 M24 1  1 
  244.   fmpy   d4,d5,d3 fadd.s d3,d1                y:(r4)+,d4.s ;    M34 1  1 
  245.   fmpy   d4,d6,d3 fadd.s d3,d1                d2.s,y:(r1)  ;    Zo  1  1 
  246.                   fadd.s d3,d1 x:(r1)+,d0.s                ;Xo      1  1 
  247.  
  248.  
  249. ; Test if point is within viewing pyramid 
  250.  
  251.   fneg.s d1                    d1.s,d2.s                   ;        1  1 
  252.   ori    #$80,ccr                                          ;        1  1 
  253.   fcmp   d1,d0                                             ;        1  1 
  254.   fcmp   d0,d2                 x:(r1)-,d5.s                ;Yo      1  1 
  255.   fcmp   d1,d5                 n0,d4.s                     ;        1  1 
  256.   fcmp   d5,d2                                y:(r1)+,d6.s ;    Zo  1  1 
  257.   fcmp   d4,d6                                             ;        1  1 
  258.   fcmp   d6,d2                                             ;        1  1 
  259.   jclr   #7,sr,_reject_entry                               ;        2  3 
  260.  
  261.  
  262. ; Calculate reciprocal 1/W 
  263.  
  264.  
  265.   fseedd d2,d6                                             ;        1  1 
  266.   fmpy.s d2,d6,d1              d9.s,d4.s                   ;        1  1 
  267.                   fsub.s d1,d4 d4.s,d3.s      d2.s,y:(r1)+ ;    Wo  1  1 
  268.   fmpy.s d1,d4,d1                                          ;        1  1 
  269.   fmpy   d6,d4,d1 fsub.s d1,d3                             ;        1  1 
  270.   fmpy.s d1,d3,d1              x:(r4)+,d4.s   y:,d3.s      ;Xs  Xf  1  1 
  271.  
  272.  
  273. ; Multiply coordinates by 1/W, scale and add offset 
  274.  
  275.  
  276.   fmpy.s d0,d4,d2                                          ;        1  1 
  277.   fmpy.s d2,d1,d2              x:(r4)+,d4.s   y:,d6.s      ;Ys  Yf  1  1 
  278.   fmpy   d5,d4,d3 fadd.s d3,d2                             ;        1  1 
  279.   fmpy.s d3,d1,d3                             d2.s,y:(r5)+ ;        1  1 
  280.                   fadd.s d6,d3 x:(r0)+,d0.s                ;        1  1 
  281.   dec    d7                                   d3.s,y:(r5)+ ;    Y1  1  1 
  282.  
  283.  
  284.  
  285.  
  286. ;--------------------------------------------------------- 
  287. ;                    Accept loop 
  288. ;--------------------------------------------------------- 
  289.  
  290.  
  291. ; Transform point to clip space 
  292.  
  293.  
  294. _accept_loop 
  295.   move                         x:(r0)+,d5.s   y:(r4)+,d4.s ;Y   M11 1  1 
  296.   fmpy.s d4,d0,d2              x:(r4)+,d3.s   y:,d4.s      ;M41 M21 1  1 
  297.   fmpy   d4,d5,d3 fadd.s d3,d2 x:(r0)+,d6.s   y:(r4)+,d4.s ;Z   M31 1  1 
  298.   fmpy   d4,d6,d3 fadd.s d3,d2                y:(r4)+,d4.s ;    M12 1  1 
  299.   fmpy   d4,d0,d1 fadd.s d3,d2 x:(r4)+,d3.s   y:,d4.s      ;M42,M22 1  1 
  300.   fmpy   d4,d5,d3 fadd.s d3,d1                y:(r4)+,d4.s ;    M32 1  1 
  301.   fmpy   d4,d6,d3 fadd.s d3,d1 d2.s,x:(r1)+   y:(r4)+,d4.s ;Xn  M13 1  1 
  302.   fmpy   d4,d0,d2 fadd.s d3,d1 x:(r4)+,d3.s   y:,d4.s      ;M43 M23 1  1 
  303.   fmpy   d4,d5,d3 fadd.s d3,d2                y:(r4)+,d4.s ;    M33 1  1 
  304.   fmpy   d4,d6,d3 fadd.s d3,d2 d1.s,x:(r1)-   y:(r4)+,d4.s ;Yn  M14 1  1 
  305.   fmpy   d4,d0,d1 fadd.s d3,d2 x:(r4)+,d3.s   y:,d4.s      ;M44 M24 1  1 
  306.   fmpy   d4,d5,d3 fadd.s d3,d1                y:(r4)+,d4.s ;    M34 1  1 
  307.   fmpy   d4,d6,d3 fadd.s d3,d1                d2.s,y:(r1)  ;    Zn  1  1 
  308.                   fadd.s d3,d1 x:(r1)+,d0.s                ;Xn      1  1 
  309.  
  310.  
  311.  
  312. ; Determine if point is within view volume 
  313.  
  314.  
  315.   fneg.s d1                    d1.s,d2.s                   ;        1  1 
  316.   ori    #$80,ccr                                          ;        1  1 
  317.   fcmp   d1,d0                                d2.s,y:(r1)  ;    Wn  1  1 
  318.   fcmp   d0,d2                 x:(r1)-,d5.s                ;Yn      1  1 
  319.   fcmp   d1,d5                 n0,d4.s                     ;        1  1 
  320.   fcmp   d5,d2                                y:(r1)-,d6.s ;    Zn  1  1 
  321.   fcmp   d4,d6                 d7.l,x:(r6)                 ;        1  1 
  322.   fcmp   d6,d2                 d6.s,d7.s                   ;        1  1 
  323.   jclr   #7,sr,_accept_clip                                ;        2  3 
  324.  
  325.  
  326. ; Calculate reciprocal 1/W 
  327.  
  328.  
  329.   fseedd d2,d6                                             ;        1  1 
  330.   fmpy.s d2,d6,d1              d9.s,d4.s                   ;        1  1 
  331.                   fsub.s d1,d4 d4.s,d3.s      d2.s,y:(r1)- ;    Wo  1  1 
  332.   fmpy.s d1,d4,d1              d0.s,x:(r1)+   d7.s,y:      ;Xo  Zo  1  1 
  333.   fmpy   d6,d4,d1 fsub.s d1,d3 d5.s,x:(r1)+                ;Yo      1  1 
  334.   fmpy.s d1,d3,d1              x:(r4)+,d4.s   y:,d3.s      ;Xs  Xf  1  1 
  335.  
  336.  
  337. ; Multiply coordinates by 1/W, scale and add offset 
  338.  
  339.  
  340.   fmpy.s d0,d4,d2                                          ;        1  1 
  341.   fmpy.s d2,d1,d2              x:(r4)+,d4.s   y:,d6.s      ;Ys  Yf  1  1 
  342.   fmpy   d5,d4,d3 fadd.s d3,d2 x:(r6),d7.l                 ;        1  1 
  343.   fmpy.s d3,d1,d3                             d2.s,y:(r5)+ ;        1  1 
  344.                   fadd.s d6,d3 x:(r0)+,d0.s                ;        1  1 
  345.   dec    d7                                   d3.s,y:(r5)+ ;    Y1  1  1 
  346.   jne    _accept_loop                                      ;        2  2 
  347.   jmp    _end                                              ;        2  2 
  348.  
  349.  
  350. ;--------------------------------------------------------- 
  351. ;            Accept loop single-clip routine 
  352. ;--------------------------------------------------------- 
  353.  
  354.  
  355. ; Dispatch to single-plane clipping routines 
  356.  
  357.  
  358. _accept_clip 
  359.   fsub.s d0,d2                 d2.s,d1.s                   ;        1  1 
  360.   fjslt  _clip1_xp                                         ;        2  2 
  361.   fadd.s d0,d1                 d1.s,d2.s                   ;        1  1 
  362.   fjslt  _clip1_xn                                         ;        2  2 
  363.   fsub.s d5,d2                 d2.s,d1.s                   ;        1  1 
  364.   fjslt  _clip1_yp                                         ;        2  2 
  365.   fadd.s d5,d1                 d1.s,d2.s                   ;        1  1 
  366.   fjslt  _clip1_yn                                         ;        2  2 
  367.   fsub.s d6,d2                 d2.s,d1.s                   ;        1  1 
  368.   fjslt  _clip1_zp                                         ;        2  2 
  369.   ftst   d6                                                ;        1  1 
  370.   fjslt  _clip1_zn                                         ;        2  2 
  371.  
  372.  
  373. ; Calculate reciprocal 1/W 
  374.  
  375.  
  376.   fseedd d1,d6                                             ;        1  1 
  377.   fmpy.s d1,d6,d1              d9.s,d4.s                   ;        1  1 
  378.                   fsub.s d1,d4 d4.s,d3.s      y:(r1)+n1,d2.s ; r1+2 1  1 
  379.   fmpy.s d1,d4,d1              x:(r1)+n1,d2.s y:,d7.s      ;Yn  Wn  1  1 
  380.   fmpy   d6,d4,d1 fsub.s d1,d3 d2.s,x:(r1)+   d7.s,y:      ;Yo  Wo  1  1 
  381.   fmpy.s d1,d3,d1              x:(r4)+,d4.s   y:,d3.s      ;Xs  Xf  1  1 
  382.  
  383.  
  384. ; Multiply coordinates by 1/W, scale and add offset 
  385.  
  386.   fmpy.s d0,d4,d2              x:(r1)+n1,d0.s y:,d7.s      ;Xn  Zn  1  1 
  387.   fmpy.s d2,d1,d2              x:(r4)+,d4.s   y:,d6.s      ;Ys  Yf  1  1 
  388.   fmpy   d5,d4,d3 fadd.s d3,d2 d0.s,x:(r1)+n1 d7.s,y:      ;Xo  Zo  1  1 
  389.   fmpy.s d3,d1,d3              x:(r6),d7.l                 ;Cnt     1  1 
  390.                   fadd.s d6,d3 x:(r0)+,d0.s   d2.s,y:(r5)+ ;X       1  1 
  391.   move                                        d3.s,y:(r5)+ ;    Y1  1  1 
  392.   dec    d7                                   n5,y:(r5)+   ;   -1.0 1  1 
  393.   jne    _reject_loop                                      ;        2  2 
  394.   jmp    _end                                              ;        2  2 
  395.  
  396. ;--------------------------------------------------------- 
  397. ;                    Reject loop 
  398. ;--------------------------------------------------------- 
  399.  
  400.  
  401. ; Transform point to clip space 
  402.  
  403. _reject_entry 
  404.   dec    d7                                   d2.s,y:(r1)+ ;    Wo  1  1 
  405.   move                         x:(r0)+,d0.s  y:(r4)+n4,d4.s ;X r4+2 1  1 
  406.  
  407. _reject_loop 
  408.   move                         x:(r0)+,d5.s  y:(r4)+,d4.s  ;Y   M11 1  1 
  409.   fmpy.s d4,d0,d2              x:(r4)+,d3.s  y:,d4.s       ;M41 M21 1  1 
  410.   fmpy   d4,d5,d3 fadd.s d3,d2 x:(r0)+,d6.s  y:(r4)+,d4.s  ;    M31 1  1 
  411.   fmpy   d4,d6,d3 fadd.s d3,d2               y:(r4)+,d4.s  ;    M12 1  1 
  412.   fmpy   d4,d0,d1 fadd.s d3,d2 x:(r4)+,d3.s  y:,d4.s       ;M42 M22 1  1 
  413.   fmpy   d4,d5,d3 fadd.s d3,d1               y:(r4)+,d4.s  ;    M32 1  1 
  414.   fmpy   d4,d6,d3 fadd.s d3,d1 d2.s,x:(r1)+  y:(r4)+,d4.s  ;Xn  M13 1  1 
  415.   fmpy   d4,d0,d2 fadd.s d3,d1 x:(r4)+,d3.s  y:,d4.s       ;M43 M23 1  1 
  416.   fmpy   d4,d5,d3 fadd.s d3,d2               y:(r4)+,d4.s  ;    M33 1  1 
  417.   fmpy   d4,d6,d3 fadd.s d3,d2 d1.s,x:(r1)-  y:(r4)+,d4.s  ;Yn  M14 1  1 
  418.   fmpy   d4,d0,d1 fadd.s d3,d2 x:(r4)+,d3.s  y:,d4.s       ;M44 M24 1  1 
  419.   fmpy   d4,d5,d3 fadd.s d3,d1               y:(r4)+,d4.s  ;    M34 1  1 
  420.   fmpy   d4,d6,d3 fadd.s d3,d1               d2.s,y:(r1)-  ;    Zn  1  1 
  421.                   fadd.s d3,d1                             ;        1  1 
  422.  
  423.  
  424. ; Determine trivial rejection 
  425.  
  426.   ori    #$e0,ccr                                          ;        1  1 
  427.   fneg.s d1                    d1.s,d5.s      y:(r1)-,d2.s ;    Wo  1  1 
  428.   fneg.s d2                    x:(r1)+n1,d6.s d2.s,d4.s    ;Xo      1  1 
  429.   fcmp   d2,d6                 x:(r1)-,d0.s                ;Xn      1  1 
  430.   fcmpg  d1,d0                 (r4)+n4                     ;r4+2    1  1 
  431.   fcmp   d6,d4                                             ;        1  1 
  432.   fcmpg  d0,d5                 x:(r1)+n1,d6.s              ;Yo      1  1 
  433.   fcmp   d2,d6                 x:(r1)+,d3.s                ;Yn      1  1 
  434.   fcmpg  d1,d3                                             ;        1  1 
  435.   fcmp   d6,d4                                             ;        1  1 
  436.   fcmpg  d3,d5                              y:(r1)+n1,d6.s ;Zo      1  1 
  437.   fcmp   d6,d4                              y:(r1)+n1,d2.s ;Zn      1  1 
  438.   fcmpg  d2,d5                 n0,d4.s                     ;        1  1 
  439.   fcmp   d4,d6                                             ;        1  1 
  440.   fcmpg  d4,d2                                             ;        1  1 
  441.   jset   #6,sr,_reject_clip                                ;        2  3 
  442.  
  443. ; Save new point 
  444.  
  445.   move                         d0.s,x:(r1)+   d2.s,y:      ;Xo Zo   1  1 
  446.   move                         d3.s,x:(r1)+   d5.s,y:      ;Yo Wo   1  1 
  447.   dec    d7                    x:(r0)+,d0.s                ;X       1  1 
  448.   jne    _reject_loop                                      ;        2  2 
  449.   jmp    _end                                              ;        2  2 
  450.  
  451.  
  452. ;--------------------------------------------------------- 
  453. ;             Reject loop clipping routine 
  454. ;--------------------------------------------------------- 
  455.  
  456. ; Determine if new point is within view volume 
  457.  
  458. _reject_clip 
  459.   ori     #$80,ccr                                         ;        1  1 
  460.   fcmp    d1,d0                (r1)-                       ;r1-     1  1 
  461.   fcmp    d1,d3                               d5.s,y:(r1)+ ;    Wn  1  1 
  462.   fcmp    d4,d2                                            ;        1  1 
  463.   fcmp    d0,d5                                            ;        1  1 
  464.   fcmp    d3,d5                                            ;        1  1 
  465.   fcmp    d2,d5                                            ;        1  1 
  466.   jclr    #7,sr,_r_clip2                                   ;        2  3 
  467.  
  468.  
  469. ;--------------------------------------------------------- 
  470. ;            Reject loop single-clip routine 
  471. ;--------------------------------------------------------- 
  472.  
  473. ; Dispatch to clipping routines 
  474.  
  475.   move                         x:(r1)+,d0.s   y:,d6.s      ;Xo  Zo  1  1 
  476.   move                         x:(r1)+n1,d5.s y:,d2.s      ;Yo  Wo  1  1 
  477.   move                         d7.l,x:(r6)                 ;Cnt     1  1 
  478.   fsub.s d0,d2                 d2.s,d1.s                   ;        1  1 
  479.   fjslt  _clip1_xp                                         ;        2  2 
  480.   fadd.s d0,d1                 d1.s,d2.s                   ;        1  1 
  481.   fjslt  _clip1_xn                                         ;        2  2 
  482.   fsub.s d5,d2                 d2.s,d1.s                   ;        1  1 
  483.   fjslt  _clip1_yp                                         ;        2  2 
  484.   fadd.s d5,d1                 d1.s,d2.s                   ;        1  1 
  485.   fjslt  _clip1_yn                                         ;        2  2 
  486.   fsub.s d6,d2                 d2.s,d1.s                   ;        1  1 
  487.   fjslt  _clip1_zp                                         ;        2  2 
  488.   ftst   d6                                                ;        1  1 
  489.   fjslt  _clip1_zn                                         ;        2  2 
  490.  
  491. ; Calculate reciprocal 1/W (old point) 
  492.  
  493.  
  494.   fseedd d1,d6                                             ;        1  1 
  495.   fmpy.s d1,d6,d1              d9.s,d4.s                   ;        1  1 
  496.                   fsub.s d1,d4                d4.s,d3.s    ;        1  1 
  497.   fmpy.s d1,d4,d1                             (r4)-n4      ;   r4-2 1  1 
  498.   fmpy   d6,d4,d1 fsub.s d1,d3                             ;        1  1 
  499.   fmpy.s d1,d3,d1              x:(r4)+,d4.s   y:,d3.s      ;Xs  Xf  1  1 
  500.  
  501.  
  502. ; Multiply coordinates by 1/W, scale and add offset (old point) 
  503.  
  504.  
  505.   fmpy.s d0,d4,d2                                          ;        1  1 
  506.   fmpy.s d2,d1,d2              x:(r4)-,d4.s y:,d6.s        ;Ys  Yf  1  1 
  507.   fmpy   d5,d4,d3 fadd.s d3,d2                             ;        1  1 
  508.   fmpy.s d3,d1,d3                           d2.s,y:(r5)+   ;    X1  1  1 
  509.                   fadd.s d6,d3              y:(r1)+n1,d2.s ;    Wn  1  1 
  510.   move                                      d3.s,y:(r5)+   ;    Y1  1  1 
  511.  
  512.  
  513. ; Calculate reciprocal 1/W (new point) 
  514.  
  515.  
  516.   fseedd d2,d6                                             ;        1  1 
  517.   fmpy.s d2,d6,d1              d9.s,d4.s                   ;        1  1 
  518.                   fsub.s d1,d4 d4.s,d3.s      d2.s,y:(r1)+ ;    Wo  1  1 
  519.   fmpy.s d1,d4,d1              x:(r1)+n1,d0.s y:,d2.s      ;Xn  Zn  1  1 
  520.   fmpy   d6,d4,d1 fsub.s d1,d3 d0.s,x:(r1)-   d2.s,y:      ;Xo  Zo  1  1 
  521.   fmpy.s d1,d3,d1              x:(r4)+,d4.s   y:,d3.s      ;Xs  Xf  1  1 
  522.  
  523.  
  524. ; Multiply coordinates by 1/W, scale and add offset (new point) 
  525.  
  526.  
  527.   fmpy.s d0,d4,d2              x:(r1)+n1,d5.s              ;Yn      1  1 
  528.   fmpy.s d2,d1,d2              x:(r4)+,d4.s   y:,d6.s      ;Ys  Yf  1  1 
  529.   fmpy   d5,d4,d0 fadd.s d3,d2 d5.s,x:(r1)+                ;Yo      1  1 
  530.   fmpy.s d0,d1,d5              x:(r0)+,d0.s   d2.s,y:(r5)+ ;X   X1  1  1 
  531.                   fadd.s d5,d3 x:(r6),d7.l                 ;Cnt     1  1 
  532.   dec    d7                                   d3.s,y:(r5)+ ;    Y1  1  1 
  533.   jne    _accept_loop                                      ;        2  2 
  534.   jmp    _end                                              ;        2  2 
  535.  
  536.  
  537. ;--------------------------------------------------------- 
  538. ;            Double point clipping routine 
  539. ;--------------------------------------------------------- 
  540.  
  541.  
  542. ; Dispatch to old point clipping routines 
  543.  
  544.  
  545. _r_clip2 
  546.   move                         d7.l,x:(r6)    y:(r1)+,d1.l ;Cnt r1+ 1  1 
  547.   move                                        y:(r1)-,d1.s ;    Wo  1  1 
  548.   move                         x:(r1)+,d5.s                ;Xo      1  1 
  549.   move                         n0,d7.s                     ;        1  1 
  550.                   fsub.s d1,d5 d5.s,d6.s                   ;        1  1 
  551.   fjsgt  _clip2_xop                                        ;        2  2 
  552.                   fadd.s d1,d6 x:(r1)-,d5.s                ;Yo      1  1 
  553.   fjslt  _clip2_xon                                        ;        2  2 
  554.                   fsub.s d1,d5 d5.s,d6.s                   ;        1  1 
  555.   fjsgt  _clip2_yop                                        ;        2  2 
  556.                   fadd.s d1,d6              y:(r1)+n1,d5.s ;Zo      1  1 
  557.   fjslt  _clip2_yon                                        ;        2  2 
  558.                   fsub.s d1,d5 d5.s,d6.s                   ;        1  1 
  559.   fjsgt  _clip2_zop                                        ;        2  2 
  560.   ftst   d6                    x:(r1)+,d5.s                ;Xn      1  1 
  561.   fjslt  _clip2_zon                                        ;        2  2 
  562.   move                                      d7.s,y:(r6)    ;    to  1  1 
  563.  
  564.  
  565. ; Dispatch to new point clipping routines 
  566.  
  567.  
  568.   move                                      y:(r1),d1.s    ;    Wn  1  1 
  569.   move                         d8.s,d7.s                   ;    tn  1  1 
  570.                   fsub.s d1,d5 d5.s,d6.s                   ;        1  1 
  571.   fjsgt  _clip2_xnp                                        ;        2  2 
  572.                   fadd.s d1,d6 x:(r1)-,d5.s                ;Yn      1  1 
  573.   fjslt  _clip2_xnn                                        ;        2  2 
  574.                   fsub.s d1,d5 d5.s,d6.s                   ;        1  1 
  575.   fjsgt  _clip2_ynp                                        ;        2  2 
  576.                   fadd.s d1,d6              y:(r1)+n1,d5.s ;Zn      1  1 
  577.   fjslt  _clip2_ynn                                        ;        2  2 
  578.                   fsub.s d1,d5 d5.s,d6.s                   ;        1  1 
  579.   fjsgt  _clip2_znp                                        ;        2  2 
  580.   ftst   d6                                                ;        1  1 
  581.   fjslt  _clip2_znn                                        ;        2  2 
  582.  
  583. ; Check for rejection 
  584.  
  585.  
  586.   move                         x:(r1)+n1,d3.s y:(r6),d5.s  ;Xo  to  1  1 
  587.   fcmp   d5,d7                 d7.s,d4.s                   ;        1  1 
  588.   fjlt   _clip2_reject                                     ;        2  2 
  589.  
  590.  
  591. ; Calculate end point coordinates: X 
  592.  
  593.  
  594.   move                         x:(r1)+n1,d6.s              ;Xn      1  1 
  595.                   fsub.s d3,d6 d6.s,x:(r1)-                ;Xo      1  1 
  596.   fmpy.s d4,d6,d1                                          ;        1  1 
  597.   fmpy   d5,d6,d2 fadd.s d3,d1 x:(r1)+n1,d6.s              ;Yn      1  1 
  598.                   fadd.s d3,d2 x:(r1),d3.s                 ;Yo      1  1 
  599.  
  600.  
  601. ; Calculate end point coordinates: Y 
  602.  
  603.  
  604.                   fsub.s d3,d6 d6.s,x:(r1)+n1 d1.s,y:(r6)+ ;Yo  Xnd 1  1 
  605.   fmpy.s d4,d6,d1              d2.s,d0.s                   ;        1  1 
  606.   fmpy   d5,d6,d2 fadd.s d3,d1              y:(r1)+n1,d6.s ;    Wn  1  1 
  607.                   fadd.s d3,d2              y:(r1)+n1,d3.s ;    Wo  1  1 
  608.  
  609.  
  610. ; Calculate end point coordinates: W 
  611.  
  612.  
  613.                   fsub.s d3,d6              d1.s,y:(r6)+   ;Ynd     1  1 
  614.   fmpy.s d4,d6,d1              d2.s,d7.s    y:(r1)+n1,d4.s ;    Wn  1  1 
  615.   fmpy   d5,d6,d2 fadd.s d3,d1              d4.s,y:(r1)+   ;    Wo  1  1 
  616.                   fadd.s d3,d2              d1.s,y:(r6)    ;Wnd     1  1 
  617.  
  618.  
  619. ; Calculate reciprocal 1/W (old point) 
  620.  
  621.  
  622.   fseedd d2,d6                                             ;        1  1 
  623.   fmpy.s d2,d6,d1              d9.s,d4.s                   ;        1  1 
  624.                   fsub.s d1,d4 d4.s,d3.s                   ;        1  1 
  625.   fmpy.s d1,d4,d1                             (r4)-n4      ;   r4-2 1  1 
  626.   fmpy   d6,d4,d1 fsub.s d1,d3                             ;        1  1 
  627.   fmpy.s d1,d3,d1              x:(r4)+,d4.s   y:,d3.s      ;Xs  Xf  1  1 
  628.  
  629.  
  630.  
  631. ; Multiply coordinates by 1/W, scale and add offset (old point) 
  632.  
  633.  
  634.   fmpy.s d0,d4,d2                                          ;        1  1 
  635.   fmpy.s d2,d1,d2              x:(r4)-,d4.s y:,d6.s        ;Ys  Yf  1  1 
  636.   fmpy   d7,d4,d3 fadd.s d3,d2              y:(r1)+n1,d4.s ;    Zn  1  1 
  637.   fmpy.s d3,d1,d3                           d4.s,y:(r1)+n1 ;    Zo  1  1 
  638.                   fadd.s d6,d3              d2.s,y:(r5)+   ;    X1  1  1 
  639.   move                                      y:(r6)-,d1.s   ;    Wnd 1  1 
  640.   move                                      d3.s,y:(r5)+   ;    Y1  1  1 
  641.  
  642.  
  643. ; Calculate reciprocal 1/W (new point) 
  644.  
  645.  
  646.   fseedd d1,d6                                             ;        1  1 
  647.   fmpy.s d1,d6,d1              d9.s,d4.s                   ;        1  1 
  648.                   fsub.s d1,d4 d4.s,d3.s     y:(r6)-,d5.s  ;    Ynd 1  1 
  649.   fmpy.s d1,d4,d1                            y:(r6),d0.s   ;    Xnd 1  1 
  650.   fmpy   d6,d4,d1 fsub.s d1,d3                             ;        1  1 
  651.   fmpy.s d1,d3,d1              x:(r4)+,d4.s  y:,d3.s       ;Xs  Xf  1  1 
  652.  
  653.  
  654. ; Multiply coordinates by 1/W, scale and add offset (old point) 
  655.  
  656.  
  657.   fmpy.s d0,d4,d2                                          ;        1  1 
  658.   fmpy.s d2,d1,d2              x:(r4)+,d4.s   y:,d6.s      ;Ys  Yf  1  1 
  659.   fmpy   d5,d4,d3 fadd.s d3,d2                             ;        1  1 
  660.   fmpy.s d3,d1,d3              x:(r6),d7.l                 ;        1  1 
  661.                   fadd.s d6,d3 x:(r0)+,d0.s   d2.s,y:(r5)+ ;X   X1  1  1 
  662.   move                                        d3.s,y:(r5)+ ;    Y1  1  1 
  663.   dec    d7                                   n5,y:(r5)+   ;   -1.0 1  1 
  664.   jne    _reject_loop                                      ;        2  2 
  665.   jmp    _end                                              ;        2  2 
  666.  
  667.  
  668.  
  669. ; Reject double-clipped line 
  670.  
  671. _clip2_reject 
  672.   move                         x:(r6),d7.l                 ;        1  1 
  673.   move                         x:(r1)+n1,d0.s y:,d1.s      ;Xn  Zn  1  1 
  674.   move                         d0.s,x:(r1)-   d1.s,y:      ;Xo  Zo  1  1 
  675.   move                         x:(r1)+n1,d0.s y:,d1.s      ;Yn  Wn  1  1 
  676.   move                         d0.s,x:(r1)+   d1.s,y:      ;Yo  Wo  1  1 
  677.   dec    d7                    x:(r0)+,d0.s                ;        1  1 
  678.   jne    _reject_loop                                      ;        2  2 
  679.  
  680.  
  681. ; Terminate endpoint list and exit 
  682.  
  683. _end 
  684.   move                         n5,d0.s                     ;-1.0    1  1 
  685.   move                         (r5)-                       ;        1  1 
  686.   move                                        y:(r5),d1.s  ;        1  1 
  687.   fcmp   d0,d1                                             ;        1  1 
  688.   fjeq  _end1                                              ;        2  2 
  689.   move                         (r5)+                       ;        1  1 
  690.  
  691. _end1 
  692.   move                         #-2.0,d0.s                  ;        2  2 
  693.   move                                        d0.s,y:(r5)+ ;        1  1 
  694.   rts                                                      ;        2  2 
  695.  
  696.  
  697. ;--------------------------------------------------------- 
  698. ;            Single point clipping routines 
  699. ;--------------------------------------------------------- 
  700.  
  701. ; x = w boundary 
  702.  
  703. _clip1_xp 
  704.   move                                        y:(r1)-,d4.s ;W1      1  1 
  705.   fmpy.s d2,d4,d3              x:(r1)+,d0.s   d2.s,d7.s    ;X1      1  1 
  706.                   fsub.s d0,d4 x:(r1)-,d0.s                ;Y1      1  1 
  707.   fmpy.s d1,d4,d1                                          ;        1  1 
  708.   fmpy   d4,d5,d2 fsub.s d3,d1 d0.s,d5.s                   ;        1  1 
  709.   fmpy.s d5,d7,d3                                          ;        1  1 
  710.   fmpy   d4,d6,d3 fsub.s d3,d2                y:(r1)+,d4.s ;Z1      1  1 
  711.   fmpy.s d4,d7,d2              d2.s,d5.s                   ;        1  1 
  712.                   fsub.s d2,d3 d1.s,d0.s                   ;        1  1 
  713.   move                         d3.s,d6.s                   ;        1  1 
  714.   rts                                                      ;        2  2 
  715.  
  716.  
  717. ; x = -w boundary 
  718.  
  719.  
  720. _clip1_xn 
  721.   move                                        y:(r1)-,d4.s ;W1      1  1 
  722.   fmpy.s d1,d4,d3              x:(r1)+,d0.s   d1.s,d7.s    ;X1      1  1 
  723.                   fadd.s d0,d4 x:(r1)-,d0.s                ;Y1      1  1 
  724.   fmpy.s d2,d4,d2                                          ;        1  1 
  725.   fmpy   d4,d5,d1 fsub.s d3,d2 d0.s,d5.s                   ;        1  1 
  726.   fmpy.s d5,d7,d3                                          ;        1  1 
  727.   fmpy   d4,d6,d3 fsub.s d3,d1                y:(r1)+,d4.s ;Z1      1  1 
  728.   fmpy.s d4,d7,d1              d1.s,d5.s                   ;        1  1 
  729.                   fsub.s d1,d3 d2.s,d0.s                   ;        1  1 
  730.   fneg.s d0                    d3.s,d6.s                   ;        1  1 
  731.   rts                                                      ;        2  2 
  732.  
  733.  
  734. ; y = w boundary 
  735.  
  736.  
  737. _clip1_yp 
  738.   move                                        y:(r1),d4.s  ;W1      1  1 
  739.   fmpy.s d2,d4,d3              x:(r1)-,d5.s   d2.s,d7.s    ;Y1      1  1 
  740.                   fsub.s d5,d4 x:(r1),d5.s                 ;X1      1  1 
  741.   fmpy.s d1,d4,d1                                          ;        1  1 
  742.   fmpy   d0,d4,d2 fsub.s d3,d1                             ;        1  1 
  743.   fmpy.s d5,d7,d3                                          ;        1  1 
  744.   fmpy   d4,d6,d3 fsub.s d3,d2                y:(r1)+,d4.s ;Z1      1  1 
  745.   fmpy.s d4,d7,d2              d2.s,d0.s                   ;        1  1 
  746.                   fsub.s d2,d3 d1.s,d5.s                   ;        1  1 
  747.   move                         d3.s,d6.s                   ;        1  1 
  748.   rts                                                      ;        2  2 
  749.  
  750.  
  751. ; y = -w boundary 
  752.  
  753.  
  754. _clip1_yn 
  755.   move                                        y:(r1),d4.s  ;W1      1  1 
  756.   fmpy.s d1,d4,d3              x:(r1)-,d5.s   d1.s,d7.s    ;Y1      1  1 
  757.                   fadd.s d5,d4 x:(r1),d5.s                 ;X1      1  1 
  758.   fmpy.s d2,d4,d2                                          ;        1  1 
  759.   fmpy   d0,d4,d1 fsub.s d3,d2                             ;        1  1 
  760.   fmpy.s d5,d7,d3                                          ;        1  1 
  761.   fmpy   d4,d6,d3 fsub.s d3,d1                y:(r1)+,d4.s ;Z1      1  1 
  762.   fmpy.s d4,d7,d1              d1.s,d0.s                   ;        1  1 
  763.                   fsub.s d1,d3 d2.s,d5.s                   ;        1  1 
  764.   fneg.s d5                    d3.s,d6.s                   ;        1  1 
  765.   rts                                                      ;        2  2 
  766.  
  767.  
  768. ; Clip at z = w boundary 
  769.  
  770.  
  771. _clip1_zp 
  772.   move                                        y:(r1)-,d4.s ;W1      1  1 
  773.   fmpy.s d2,d4,d3              d2.s,d7.s      y:(r1),d6.s  ;Z1      1  1 
  774.                   fsub.s d6,d4 x:(r1)+,d6.s                ;X1      1  1 
  775.   fmpy.s d1,d4,d1                                          ;        1  1 
  776.   fmpy   d0,d4,d2 fsub.s d3,d1                             ;        1  1 
  777.   fmpy.s d6,d7,d3                                          ;        1  1 
  778.   fmpy   d4,d5,d3 fsub.s d3,d2 x:(r1),d4.s                 ;Y1      1  1 
  779.   fmpy.s d4,d7,d2              d2.s,d0.s                   ;        1  1 
  780.                   fsub.s d2,d3 d1.s,d6.s                   ;        1  1 
  781.   move                         d3.s,d5.s                   ;        1  1 
  782.   rts                                                      ;        2  2 
  783.  
  784.  
  785. ; Clip at z = 0 boundary 
  786.  
  787.  
  788. _clip1_zn 
  789.   move                                        y:(r1)-,d2.s ;W1      1  1 
  790.   fmpy.s d2,d6,d2                             y:(r1),d4.s  ;Z1      1  1 
  791.   fmpy.s d1,d4,d1              x:(r1)+,d7.s                ;X1      1  1 
  792.   fmpy   d0,d4,d2 fsub.s d2,d1                             ;        1  1 
  793.   fmpy.s d6,d7,d0              x:(r1),d7.s                 ;Y1      1  1 
  794.   fmpy   d6,d7,d3 fsub.s d0,d2                             ;        1  1 
  795.   fmpy.s d4,d5,d5              d2.s,d0.s                   ;        1  1 
  796.                   fsub.s d3,d5 n0,d6.s                     ;        1  1 
  797.   rts                                                      ;        2  2 
  798.  
  799.  
  800.  
  801. ;--------------------------------------------------------- 
  802. ;             Double point clipping routines 
  803. ;--------------------------------------------------------- 
  804.  
  805.  
  806. ; XOld = WOld boundary 
  807.  
  808.  
  809. _clip2_xop 
  810.   move                         (r1)+n1                     ;        1  1 
  811.   move                                        y:(r1)-,d3.s ;Wn      1  1 
  812.                   fadd.s d3,d5 x:(r1)-,d3.s   d5.s,d0.s    ;Xn      1  1 
  813.                   fsub.s d3,d5                             ;        1  1 
  814.   fseedd d5,d4                                             ;        1  1 
  815.   fmpy.s d5,d4,d5              d9.s,d2.s                   ;        1  1 
  816.   fmpy   d0,d4,d0 fsub.s d5,d2 d2.s,d3.s                   ;        1  1 
  817.   fmpy.s d5,d2,d5              d2.s,d4.s                   ;        1  1 
  818.   fmpy   d0,d4,d0 fsub.s d5,d3                             ;        1  1 
  819.   fmpy.s d0,d3,d0                                          ;        1  1 
  820.   fcmp   d7,d0                                             ;        1  1 
  821.   ftfr.s d0,d7    ffgt                                     ;        1  1 
  822.   rts                                                      ;        2  2 
  823.  
  824.  
  825. ; XOld = -WOld boundary 
  826.  
  827.  
  828. _clip2_xon 
  829.   move                         (r1)-                       ;        1  1 
  830.   move                                        y:(r1)-,d3.s ;Wn      1  1 
  831.                   fsub.s d3,d6 x:(r1)+n1,d3.s d6.s,d0.s    ;Xn      1  1 
  832.                   fsub.s d3,d6                             ;        1  1 
  833.   fseedd d6,d4                                             ;        1  1 
  834.   fmpy.s d6,d4,d6              d9.s,d2.s                   ;        1  1 
  835.   fmpy   d0,d4,d0 fsub.s d6,d2 d2.s,d3.s                   ;        1  1 
  836.   fmpy.s d6,d2,d6              d2.s,d4.s                   ;        1  1 
  837.   fmpy   d0,d4,d0 fsub.s d6,d3                             ;        1  1 
  838.   fmpy.s d0,d3,d0                                          ;        1  1 
  839.   fcmp   d7,d0                                             ;        1  1 
  840.   ftfr.s d0,d7    ffgt                                     ;        1  1 
  841.   rts                                                      ;        2  2 
  842.  
  843.  
  844. ; YOld = WOld boundary 
  845.  
  846.  
  847. _clip2_yop 
  848.   move                         (r1)-                       ;        1  1 
  849.   move                                        y:(r1),d3.s  ;Wn      1  1 
  850.                   fadd.s d3,d5 x:(r1)+,d3.s   d5.s,d0.s    ;Yn      1  1 
  851.                   fsub.s d3,d5                             ;        1  1 
  852.   fseedd d5,d4                                             ;        1  1 
  853.   fmpy.s d5,d4,d5              d9.s,d2.s                   ;        1  1 
  854.   fmpy   d0,d4,d0 fsub.s d5,d2 d2.s,d3.s                   ;        1  1 
  855.   fmpy.s d5,d2,d5              d2.s,d4.s                   ;        1  1 
  856.   fmpy   d0,d4,d0 fsub.s d5,d3                             ;        1  1 
  857.   fmpy.s d0,d3,d0                                          ;        1  1 
  858.   fcmp   d7,d0                                             ;        1  1 
  859.   ftfr.s d0,d7    ffgt                                     ;        1  1 
  860.   rts                                                      ;        2  2 
  861.  
  862.  
  863. ; YOld = -WOld boundary 
  864.  
  865.  
  866. _clip2_yon 
  867.   move                         (r1)+                       ;        1  1 
  868.   move                                        y:(r1),d3.s  ;Wn      1  1 
  869.                   fsub.s d3,d6 x:(r1)-,d3.s   d6.s,d0.s    ;Yn      1  1 
  870.                   fsub.s d3,d6                             ;        1  1 
  871.   fseedd d6,d4                                             ;        1  1 
  872.   fmpy.s d6,d4,d6              d9.s,d2.s                   ;        1  1 
  873.   fmpy   d0,d4,d0 fsub.s d6,d2 d2.s,d3.s                   ;        1  1 
  874.   fmpy.s d6,d2,d6              d2.s,d4.s                   ;        1  1 
  875.   fmpy   d0,d4,d0 fsub.s d6,d3                             ;        1  1 
  876.   fmpy.s d0,d3,d0                                          ;        1  1 
  877.   fcmp   d7,d0                                             ;        1  1 
  878.   ftfr.s d0,d7    ffgt                                     ;        1  1 
  879.   rts                                                      ;        2  2 
  880.  
  881.  
  882.  
  883. ; ZOld = WOld boundary 
  884.  
  885. _clip2_zop 
  886.   move                         (r1)+                       ;        1  1 
  887.   move                                        y:(r1)-,d3.s ;Wn      1  1 
  888.                   fadd.s d3,d5 d5.s,d0.s      y:(r1),d3.s  ;Zn      1  1 
  889.                   fsub.s d3,d5                             ;        1  1 
  890.   fseedd d5,d4                                             ;        1  1 
  891.   fmpy.s d5,d4,d5              d9.s,d2.s                   ;        1  1 
  892.   fmpy   d0,d4,d0 fsub.s d5,d2 d2.s,d3.s                   ;        1  1 
  893.   fmpy.s d5,d2,d5              d2.s,d4.s                   ;        1  1 
  894.   fmpy   d0,d4,d0 fsub.s d5,d3                             ;        1  1 
  895.   fmpy.s d0,d3,d0                                          ;        1  1 
  896.   fcmp   d7,d0                                             ;        1  1 
  897.   ftfr.s d0,d7    ffgt                                     ;        1  1 
  898.   rts                                                      ;        2  2 
  899.  
  900.  
  901. ; ZOld = 0 boundary 
  902.  
  903. _clip2_zon 
  904.   move                         (r1)-                       ;        1  1 
  905.   move                                        y:(r1)+,d3.s ;Zn      1  1 
  906.                   fsub.s d3,d6 d6.s,d0.s                   ;        1  1 
  907.   fseedd d6,d4                                             ;        1  1 
  908.   fmpy.s d6,d4,d6              d9.s,d2.s                   ;        1  1 
  909.   fmpy   d0,d4,d0 fsub.s d6,d2 d2.s,d3.s                   ;        1  1 
  910.   fmpy.s d6,d2,d6              d2.s,d4.s                   ;        1  1 
  911.   fmpy   d0,d4,d0 fsub.s d6,d3                             ;        1  1 
  912.   fmpy.s d0,d3,d0                                          ;        1  1 
  913.   fcmp   d7,d0                                             ;        1  1 
  914.   ftfr.s d0,d7    ffgt                                     ;        1  1 
  915.   rts                                                      ;        2  2 
  916.  
  917.  
  918. ; XNew = WNew boundary 
  919.  
  920. _clip2_xnp 
  921.   move                         (r1)+n1                     ;        1  1 
  922.   move                                        y:(r1)-,d0.s ;Wo      1  1 
  923.   move                         x:(r1)-,d2.s                ;Xo      1  1 
  924.                   fsub.s d2,d0                             ;        1  1 
  925.                   fadd.s d0,d5                             ;        1  1 
  926.   fseedd d5,d4                                             ;        1  1 
  927.   fmpy.s d5,d4,d5              d9.s,d2.s                   ;        1  1 
  928.   fmpy   d0,d4,d0 fsub.s d5,d2 d2.s,d3.s                   ;        1  1 
  929.   fmpy.s d5,d2,d5              d2.s,d4.s                   ;        1  1 
  930.   fmpy   d0,d4,d0 fsub.s d5,d3                             ;        1  1 
  931.   fmpy.s d0,d3,d0                                          ;        1  1 
  932.   fcmp   d7,d0                                             ;        1  1 
  933.   ftfr.s d0,d7    fflt                                     ;        1  1 
  934.   rts                                                      ;        2  2 
  935.  
  936. ; XNew = -WNew boundary 
  937.  
  938. _clip2_xnn 
  939.   move                         (r1)-                       ;        1  1 
  940.   move                                        y:(r1)-,d3.s ;Wo      1  1 
  941.   move                         x:(r1)+n1,d2.s              ;Xo      1  1 
  942.                   fadd.s d3,d2                             ;        1  1 
  943.                   fsub.s d6,d2 d2.s,d0.s                   ;        1  1 
  944.   fseedd d2,d4                                             ;        1  1 
  945.   fmpy.s d2,d4,d6              d9.s,d2.s                   ;        1  1 
  946.   fmpy   d0,d4,d0 fsub.s d6,d2 d2.s,d3.s                   ;        1  1 
  947.   fmpy.s d6,d2,d6              d2.s,d4.s                   ;        1  1 
  948.   fmpy   d0,d4,d0 fsub.s d6,d3                             ;        1  1 
  949.   fmpy.s d0,d3,d0                                          ;        1  1 
  950.   fcmp   d7,d0                                             ;        1  1 
  951.   ftfr.s d0,d7    fflt                                     ;        1  1 
  952.   rts                                                      ;        2  2 
  953.  
  954.  
  955. ; YNew = WNew boundary 
  956.  
  957. _clip2_ynp 
  958.   move                         (r1)-                       ;        1  1 
  959.   move                         x:(r1)+,d2.s   y:,d0.s      ;Yo  Wo  1  1 
  960.                   fsub.s d2,d0                             ;        1  1 
  961.                   fadd.s d0,d5                             ;        1  1 
  962.   fseedd d5,d4                                             ;        1  1 
  963.   fmpy.s d5,d4,d5              d9.s,d2.s                   ;        1  1 
  964.   fmpy   d0,d4,d0 fsub.s d5,d2 d2.s,d3.s                   ;        1  1 
  965.   fmpy.s d5,d2,d5              d2.s,d4.s                   ;        1  1 
  966.   fmpy   d0,d4,d0 fsub.s d5,d3                             ;        1  1 
  967.   fmpy.s d0,d3,d0                                          ;        1  1 
  968.   fcmp   d7,d0                                             ;        1  1 
  969.   ftfr.s d0,d7    fflt                                     ;        1  1 
  970.   rts                                                      ;        2  2 
  971.  
  972.  
  973. ; YNew = -WNew boundary 
  974.  
  975. _clip2_ynn 
  976.   move                         (r1)+                       ;        1  1 
  977.   move                         x:(r1)-,d2.s   y:,d3.s      ;Yo  Wo  1  1 
  978.                   fadd.s d3,d2                             ;        1  1 
  979.                   fsub.s d6,d2 d2.s,d0.s                   ;        1  1 
  980.   fseedd d2,d4                                             ;        1  1 
  981.   fmpy.s d2,d4,d6              d9.s,d2.s                   ;        1  1 
  982.   fmpy   d0,d4,d0 fsub.s d6,d2 d2.s,d3.s                   ;        1  1 
  983.   fmpy.s d6,d2,d6              d2.s,d4.s                   ;        1  1 
  984.   fmpy   d0,d4,d0 fsub.s d6,d3                             ;        1  1 
  985.   fmpy.s d0,d3,d0                                          ;        1  1 
  986.   fcmp   d7,d0                                             ;        1  1 
  987.   ftfr.s d0,d7    fflt                                     ;        1  1 
  988.   rts                                                      ;        2  2 
  989.  
  990. ; ZNew = WNew boundary 
  991.  
  992.  
  993. _clip2_znp 
  994.   move                         (r1)+                       ;        1  1 
  995.   move                                        y:(r1)-,d0.s ;Wo      1  1 
  996.   move                                        y:(r1),d2.s  ;Zo      1  1 
  997.                   fsub.s d2,d0                             ;        1  1 
  998.                   fadd.s d0,d5                             ;        1  1 
  999.   fseedd d5,d4                                             ;        1  1 
  1000.   fmpy.s d5,d4,d5              d9.s,d2.s                   ;        1  1 
  1001.   fmpy   d0,d4,d0 fsub.s d5,d2 d2.s,d3.s                   ;        1  1 
  1002.   fmpy.s d5,d2,d5              d2.s,d4.s                   ;        1  1 
  1003.   fmpy   d0,d4,d0 fsub.s d5,d3                             ;        1  1 
  1004.   fmpy.s d0,d3,d0                                          ;        1  1 
  1005.   fcmp   d7,d0                                             ;        1  1 
  1006.   ftfr.s d0,d7    fflt                                     ;        1  1 
  1007.   rts                                                      ;        2  2 
  1008.  
  1009.  
  1010. ; ZNew = 0 boundary 
  1011.  
  1012.  
  1013. _clip2_znn 
  1014.   move                         d6.s,d0.s      y:(r1),d6.s  ;Zo      1  1 
  1015.                   fsub.s d0,d6 d6.s,d0.s                   ;        1  1 
  1016.   fseedd d6,d4                                             ;        1  1 
  1017.   fmpy.s d6,d4,d6              d9.s,d2.s                   ;        1  1 
  1018.   fmpy   d0,d4,d0 fsub.s d6,d2 d2.s,d3.s                   ;        1  1 
  1019.   fmpy.s d6,d2,d6              d2.s,d4.s                   ;        1  1 
  1020.   fmpy   d0,d4,d0 fsub.s d6,d3                             ;        1  1 
  1021.   fmpy.s d0,d3,d0                                          ;        1  1 
  1022.   fcmp   d7,d0                                             ;        1  1 
  1023.   ftfr.s d0,d7    fflt                                     ;        1  1 
  1024.   rts                                                      ;        2  2 
  1025.